package com.suse.rabbitmqspringboot.controller;

import com.suse.rabbitmqspringboot.constant.Constants;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/producer")
@RestController
public class producerController {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @RequestMapping("/work")
    public String work() {
        for(int i = 0; i < 10; i++) {
            // 使用内置交换机， RoutingKey 和队列名称一致
            rabbitTemplate.convertAndSend("", Constants.WORK_QUEUE, "hello spring amqp : work..." + i);
        }

        return "发送成功";
    }
}
